// ActionScript file

import com.nstar.base.util.GraphicsUtils;

import mx.collections.ArrayCollection;
import mx.formatters.NumberFormatter;


public var total:Number = 0;
public var got:Number = 0;
public var rate:Number = 0;


private var formater:NumberFormatter = new NumberFormatter();

private function init():void{
	formater.precision = 2;
	
	this.invalidateDisplayList();
}

public function updateTotalMoney(value:String):void{
	total += Number(value);//累计总金额
	this.invalidateDisplayList();
}

public function updateGotMoney(gotMoneys:String,value:Number):void{
	got += Number(gotMoneys);//累计捡到的
	updateCount(value);
	this.invalidateDisplayList();
}


public function reset():void{
	total = 0;
	got = 0;

	for each(var item:Object in list.dataProvider){
		item.count = 0;
	}	
	this.invalidateDisplayList();
}

override protected function updateDisplayList(unscaledWidth:Number,
                                                  unscaledHeight:Number):void{
	super.updateDisplayList(unscaledWidth,unscaledHeight);
	GraphicsUtils.drawBackground(imgBg,board);
	GraphicsUtils.drawBackground(imgBg,valueList);
	
	var nf:NumberFormatter = new NumberFormatter();
	nf.useThousandsSeparator = false;
	nf.precision = 1;
	lblTotal.text = nf.format(total);
	lblGot.text =  nf.format(got);
	
	var v:Number = got*100/total;
	var s:String = formater.format(v);
	if(s=="") s = "0.00";
	
//	lblRate.text =  s +"%"; 	
} 

public function updateMoneyType(values:ArrayCollection):void{
	list.dataProvider = values;
}

public function updateCount(value:Number):void{
	for each(var item:Object in list.dataProvider){
		if(item.value == value){
			item.count += 1;
		}
	}
}

public function updateNext(names:String,value:Number):void{
	txtNext.toolTip = "下一关出现的对象："+names;
	txtNext.text = value.toString();
	this.validateNow();
}

